Adding grid controls

To add a grid to your form follow next steps:

  1. Arrange a ListControl in your form.
  2. Set the following styles for the grid: View: Report, Align: top, Sort: none, Single selection, Owner draw fixed
  3. In OnInitialUpdate(), open the cursor of the table for the grid specifying the parameter for filtering the records.
  4. Add the columns you need to the grid specifying fields and width.

The following example will edit Desc, Quant and Price fields of the table Orders_r filtering the records using IdOrder, this field is present in both tables master and rows table.

OpenCursor( "SELECT * FROM [Orders]");

OpenCursor( "SELECT * FROM [Orders_r]", "IdOrder = 1");

AddListCtrl( IDC_LIST_ROW, "IdOrd", 2, "IdOrder");

AddListCol( IDC_LIST_ROW, "Desc", 100);

AddListCol( IDC_LIST_ROW, "Quant", 50);

AddListCol( IDC_LIST_ROW, "Price", 50);

The following example adds rows to the grid whose Id is IDC_LIST_ROW.

void CFormOrders::OnButAddRow()

{

CDBGrid * pDBGrid = (CDBGrid *) GetDlgItem(IDC_LIST_ROW);
ASSERT_VALID( pDBGrid );
pDBGrid->AddRecord();

}